<template>
  <PageHeaderNew :title="title" :breadCrumb="breadCrumb" :showBack="true">
    <template #buts>
      <a-button type="primary" @click="goInternshipTemplateDetail()">
        新增模板
      </a-button>
    </template>
  </PageHeaderNew>
  <div :style="{ margin: '20px' }">
    实习证明开具方式
    <a-radio-group v-model="value" @change="changeMode">
      <a-radio value="1">
        <template #radio="{ checked }">
          <a-space
            align="start"
            class="custom-radio-card"
            :class="{ 'custom-radio-card-checked': checked }"
          >
            <div className="custom-radio-card-mask">
              <div className="custom-radio-card-mask-dot" />
            </div>
            <div>
              <div className="custom-radio-card-title">员工自助</div>
              <a-typography-text type="secondary">
                <!-- this is a text -->
              </a-typography-text>
            </div>
          </a-space>
        </template>
      </a-radio>
      <a-radio value="2">
        <template #radio="{ checked }">
          <a-space
            align="start"
            class="custom-radio-card"
            :class="{ 'custom-radio-card-checked': checked }"
          >
            <div className="custom-radio-card-mask">
              <div className="custom-radio-card-mask-dot" />
            </div>
            <div>
              <div className="custom-radio-card-title">审核制</div>
              <a-typography-text type="secondary">
                <!-- this is a text -->
              </a-typography-text>
            </div>
          </a-space>
        </template>
      </a-radio>
    </a-radio-group>
    <div class="base-setting-warp">
      <KeepAlive>
        <component :is="conponentName" />
      </KeepAlive>
    </div>
  </div>
</template>

<style scoped>
.custom-radio-card {
  padding: 10px 16px;
  border: 1px solid var(--color-border-2);
  border-radius: 4px;
  width: 250px;
  box-sizing: border-box;
}

.custom-radio-card-mask {
  height: 14px;
  width: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 100%;
  border: 1px solid var(--color-border-2);
  box-sizing: border-box;
}

.custom-radio-card-mask-dot {
  width: 8px;
  height: 8px;
  border-radius: 100%;
}

.custom-radio-card-title {
  color: var(--color-text-1);
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 8px;
}

.custom-radio-card:hover,
.custom-radio-card-checked,
.custom-radio-card:hover .custom-radio-card-mask,
.custom-radio-card-checked .custom-radio-card-mask {
  border-color: rgb(var(--primary-6));
}

.custom-radio-card-checked {
  background-color: var(--color-primary-light-1);
}

.custom-radio-card:hover .custom-radio-card-title,
.custom-radio-card-checked .custom-radio-card-title {
  color: rgb(var(--primary-6));
}

.custom-radio-card-checked .custom-radio-card-mask-dot {
  background-color: rgb(var(--primary-6));
}
</style>

<script setup lang="ts">
import * as apiVariation from '@/apis/human/base/variationManager';
import { useRouter } from 'vue-router';
import { Message } from '@arco-design/web-vue';
import { TEditInternshipTemplate } from '@/apis/human/base/variationManager/type';
import EmployeeSelfService from './components/EmployeeSelfService.vue';
import AuditSystem from './components/AuditSystem.vue';

const router = useRouter();
const title = '实习证明开具方式配置';
const breadCrumb: string[] = ['人事', '异动管理', '实习证明开具方式配置'];
const value = ref('');
const templateList = ref<TEditInternshipTemplate[]>([]);
const conponentName = computed(() => {
  //方式1员工自助
  if (value.value === '1') {
    return EmployeeSelfService;
  }
  //方式2审核制
  if (value.value === '2') {
    return AuditSystem;
  }
  return '';
});
watch(
  () => conponentName.value,
  (val) => {
    console.log(val, 'sfs');
  }
);
//获取模板方式
const getInternshipProofMode = async () => {
  let res = await apiVariation.GetInternshipProofMode();
  value.value = res.Value;
};
//切换证明开具方式
const changeMode = async () => {
  await apiVariation.PostInternshipProofMode({ value: value.value });
  Message.success('修改成功');
};
//去新增模板
const goInternshipTemplateDetail = (data?: TEditInternshipTemplate) => {
  let id = data && data.id! > 0 ? data.id : void 0;
  router.push({
    name: 'InternshipTemplateDetail',
    query: { id }
  });
};
getInternshipProofMode();
</script>
<style lang="less" scoped>
.base-setting-warp {
  display: flex;
  flex-wrap: wrap;
  margin-top: 16px;
}
</style>
